package com.e3.web.index.client;

import com.e3.web.core.client.GXTHelper;
import com.e3.web.core.client.GxtClientSession;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Status;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.Element;

public class MainStatusBar extends LayoutContainer{
	
	private ToolBar toolBar = new ToolBar();
	
	private Status messageStatus = new Status();
	
	private Status companyStatus = new Status();
	
	private Status userStatus = new Status();
	
	private Status workingDateStatus = new Status();
		
	public MainStatusBar(){
	}
	
	@Override
	protected void onRender(Element parent, int index){
		super.onRender(parent, index);
		
		toolBar.setSpacing(2);
		
		messageStatus.setText(MainMessages.INSTANCE.lab_system_info());
		messageStatus.setBox(true);
		messageStatus.setWidth(200);
		toolBar.add(messageStatus);
		toolBar.add(new FillToolItem());
		
		LabelToolItem comanySt = new LabelToolItem(MainMessages.INSTANCE.lab_company());
		toolBar.add(comanySt);
		companyStatus.setBox(true);
		companyStatus.setWidth(300);
		toolBar.add(companyStatus);
		
		LabelToolItem userSt = new LabelToolItem(MainMessages.INSTANCE.lab_user());
		toolBar.add(userSt);
		userStatus.setBox(true);
		userStatus.setWidth(250);
		toolBar.add(userStatus);
		
		LabelToolItem dateSt = new LabelToolItem(MainMessages.INSTANCE.lab_workdate());
		toolBar.add(dateSt);
		workingDateStatus.setBox(true);
		workingDateStatus.setWidth(250);
		toolBar.add(workingDateStatus);
		
		add(toolBar);
		
		initStatusContent();
	}
	
	private void initStatusContent() {
		GxtClientSession cSession = GXTHelper.getClientSession();
		String companyName = cSession.getCorpName();
		if(companyName==null||companyName.equals("")){
			companyName = cSession.getCorpCode();
		}
		setCompany(companyName);
		
		String userName = cSession.getUserName();
		if(userName == null||userName.equals("")){
			userName = cSession.getUserCode();
		}
		setUser(userName);
		
		setWorkingDate(cSession.getLoginTime());
	}

	public void setCompany(String companyName){
		companyStatus.setText(companyName);
		companyStatus.setToolTip(companyStatus.getText());
	}
	
	public void setUser(String userName){
		userStatus.setText(userName);
		userStatus.setToolTip(userStatus.getText());
	}
	
	public void setMessage(String message){
		messageStatus.setText(message);
		messageStatus.setToolTip(messageStatus.getText());
	}
	
	public void setWorkingDate(String date){
		workingDateStatus.setText(date);
		workingDateStatus.setToolTip(workingDateStatus.getText());
	}

}